#include "Map1.h"


Map1::Map1()
{
	m_Sprite = Source::getInstance()->getSprite(IDImage::IMG_MAP1);
	m_CheckCollision = new Collision();

	m_Vpy = VIEW_PORT_Y;

	m_Bridge = new Bridge(50, 100);
}

void Map1::Init(CKeyBoard *keyboard)
{
	MapObject::Init(keyboard, NodeTileMap_1);

	m_hero = new CBlue(54,140);
	m_soldier = new Soldier();

	for (int i = 0; i < Array.size(); i++)
	{
		if (Array[i].m_Id == ID_BLOCK_ITEM)
		{
			ITem *item = new ItemBlock(IDITem::M_Item, Array[i].m_X, Array[i].m_Y);
			m_FrameITem.push_back(item);
		}
		else if (Array[i].m_Id == ID_BLOCK_TANK )
		{
			Character *blocktank = new BlockTank(Array[i].m_X, Array[i].m_Y);
			m_FrameEnemy.push_back(blocktank);
		}
		else if (Array[i].m_Id == ID_TANK)
		{
			Character *blocktank2 = new BlockTank2(Array[i].m_X, Array[i].m_Y);
			m_FrameEnemy.push_back(blocktank2);
		}
		else if (Array[i].m_Id == ID_SOLDIER_SNIPER)
		{
			Character *soldiersniper = new SoldierSniper(Array[i].m_X, Array[i].m_Y);
			m_FrameEnemy.push_back(soldiersniper);
		}
	}
}

void Map1::Update()
{
	m_hero->InputKey(*m_keyboard);
	
	m_hero->UpdateCollisionMap(Array);
	m_hero->Update();

	m_soldier->UpdateCollisionMap(Array);
	m_soldier->Update();

	for (int i = 0; i < m_FrameITem.size(); i++)
	{
		m_FrameITem[i]->Update();
	}

	for (int i = 0; i < m_FrameEnemy.size(); i++)
	{
		m_FrameEnemy[i]->UpdateAnimation(m_hero->getPosition_X(), m_hero->getPosition_Y());
		m_FrameEnemy[i]->Update();
	}
}

void Map1::Draw(LPD3DXSPRITE SpriteHandler)
{
	m_Vpx = m_hero->getVpx();
	

	for (vector<ObjectTittle>::iterator i = Array.begin(); i != Array.end(); i++)
	{
		m_Sprite->setIndex((*i).m_Index);
		m_Position.x = (*i).m_X;
		m_Position.y = (*i).m_Y;

		CObject::Draw(SpriteHandler);
	}

	for (int i = 0; i < m_FrameITem.size(); i++)
	{
		m_FrameITem[i]->setCamera(m_Vpx, m_Vpy);
		m_FrameITem[i]->Draw(SpriteHandler);
	}

	for (int i = 0; i < m_FrameEnemy.size(); i++)
	{
		m_FrameEnemy[i]->setCamera(m_Vpx, m_Vpy);
		m_FrameEnemy[i]->Draw(SpriteHandler);
	}

	m_Bridge->Draw(SpriteHandler);

	m_hero->Draw(SpriteHandler);
	m_soldier->Draw(SpriteHandler);
}
Map1::~Map1()
{
}
